<%@page import="com.mto.module.karaoke.model.Category"%>
<%@page import="java.util.List"%>
<%@page import="com.mto.module.karaoke.service.CategoryServiceUtil"%>
<%@page import="com.mto.module.karaoke.service.CategoryLocalServiceUtil"%>
<%@ include file="/jsps/main.jsp"%>

<%
PortletURL actionUrl = renderResponse.createActionURL();
PortletURL renderUrl = renderResponse.createRenderURL();

actionUrl.setParameter(ActionRequest.ACTION_NAME, "updateSong");
PortletURL redirectUrl = renderResponse.createRenderURL();
redirectUrl.setParameter("jspPage", "/jsps/quan-tri/view.jsp");
actionUrl.setParameter("redirectUrl", redirectUrl.toString());

long songId = ParamUtil.getLong(request, "songId");
Song song = null;
String songName = "", songAuthor = "", songSinger = "", recordNumber = "",audioUrl="", 
action = "save", strSongId = String.valueOf(songId);
Integer songCategory = 0;

if(songId > 0) {
	song = SongLocalServiceUtil.getSong(songId);
	songName = song.getSongName();
	songAuthor = song.getSongAuthor();
	songCategory = song.getSongCategory();
	songSinger = song.getSongSinger();
	recordNumber = String.valueOf(song.getRecordNumber());
	audioUrl = song.getAudioUrl();
	action = "update";
}
//category
List<Category> categories= CategoryLocalServiceUtil.getCategories(0, CategoryLocalServiceUtil.getCategoriesCount());
%>

<aui:layout cssClass="portlet-layout">
	<aui:column cssClass="aui-w20 portlet-column portlet-column-first">
		<div class="portlet-column-content portlet-column-content-first">
			<ul class="karaoke-menu">
				<% 
				renderUrl.setParameter("jspPage", "/jsps/quan-tri/list.jsp"); 
				%>
				<li><a href="<%=renderUrl.toString()%>"><liferay-ui:message key="danh-sach-cac-bai-hat"/></a></li>
				
				<c:if test="<%= song != null %>">
					<% 
					renderUrl.setParameter("jspPage", "/jsps/quan-tri/update.jsp"); 
					%>
					<li><a href="<%=renderUrl.toString()%>"><liferay-ui:message key="tao-bai-hat"/></a></li>
					
					<% 
					renderUrl.setParameter("jspPage", "/jsps/quan-tri/view.jsp"); 
					renderUrl.setParameter("songId", strSongId);
					%>
					<li><a href="<%=renderUrl.toString()%>"><liferay-ui:message key="xem-bai-hat"/></a></li>
				</c:if>
			</ul>
		</div>
			
	</aui:column>
	<aui:column cssClass="aui-w80 portlet-column portlet-column-last">
		<div class="portlet-column-content portlet-column-content-last">
			
			<liferay-ui:error key="songName-required" message="songName-required" />
			<liferay-ui:error key="songAuthor-required" message="songAuthor-required" />
			<liferay-ui:error key="songCategory-required" message="songCategory-required" />
			<liferay-ui:error key="file-required" message="file-required" />
			
			<aui:form action="<%=actionUrl.toString() %>" enctype="multipart/form-data" >
				<aui:fieldset>
					<aui:input name="songId" value="<%=songId %>" type="hidden"/>
					<aui:input name="songName" inputCssClass="input-100" label="songName" value="<%=songName %>"/>
					<aui:input name="songAuthor" inputCssClass="input-100" label="songAuthor" value="<%=songAuthor %>"/>
<%-- 					<aui:input name="songCategory" inputCssClass="input-100" label="songCategory" value="<%=songCategory %>"/> --%>
					<aui:select name="songCategory" inputCssClass="input-100" label="songCategory">
						 <%for(Category category : categories) {%>
						 	<aui:option value="<%=category.getCategoryId() %>" label="<%=category.getName() %>"> </aui:option>
						 <%} %>
						 
					</aui:select>
					<aui:input name="songSinger" inputCssClass="input-100" label="songSinger" value="<%=songSinger %>"/>
					<aui:input name="audio" inputCssClass="input-100" type="file" label="File (.mp3)" ></aui:input>
					<aui:input name="file" inputCssClass="input-100" type="file" label="Lyric" />
					<aui:button type="submit" value="<%=action %>"/>
				</aui:fieldset>
			</aui:form>
		</div>
	</aui:column>
</aui:layout>